#include <bits/stdc++.h>

using namespace std;
class Solution {
   public:
    int maxProduct(vector<string>& words) {
        unordered_map<int, int> m;
        for_each(words.begin(), words.end(), [&](string& s) {
            int mask = 0;
            for_each(s.begin(), s.end(), [&](char c) {
                mask |= 1 << (c - 'a');
            });
            m[mask] = max(m[mask], (int)s.size());
        });
        int ret = 0;
        for (auto it = m.begin(); it != m.end(); ++it) {
            for (auto jt = m.begin(); jt != m.end(); ++jt) {
                if (it == jt) {
                    continue;
                }
                if ((it->first & jt->first) == 0) {
                    ret = max(ret, it->second * jt->second);
                }
            }
        }
        return ret;
    }
};
